package cn.kgc.airmanager.service.impl;


import cn.kgc.airmanager.mapper.AirMapper;
import cn.kgc.airmanager.pojo.Air;
import cn.kgc.airmanager.pojo.AirExample;
import cn.kgc.airmanager.service.AirService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class AirServiceImpl implements AirService {
    @Resource
    AirMapper airMapper;
    @Override
    public PageInfo<Air> select(Integer pageNum, Integer pageSize, Integer districtId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Air> airList;
        if(districtId!=0){
            AirExample example=new AirExample();
            AirExample.Criteria criteria=example.createCriteria();
            criteria.andDistrictidEqualTo(districtId);
            airList=airMapper.selectByExample1(example);
        }else{
            airList=airMapper.selectByExample1(null);
        }
        PageInfo<Air> pageInfo=new PageInfo<>(airList);
        return pageInfo;
    }

    @Override
    public Integer add(Air air) {
        int i=airMapper.insert(air);
        return i;
    }

    @Override
    public Air selectById(Integer id) {
        Air air=airMapper.selectByPrimaryKey(id);
        return air;
    }

    @Override
    public Integer update(Air air) {
        int i=airMapper.updateByPrimaryKey(air);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=airMapper.deleteByPrimaryKey(id);
        return i;
    }
}
